// components/header/index.js
const app = getApp()
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    // 标题
    title: {
      type: String,
      value: '草图里'
    },
    // 路径
    path: {
      type: String,
      value: ''
    },
    // 背景色
    background: {
      type: String,
      value: '#1A1A1A'
    },
    // 文字颜色
    color: {
      type: String,
      value: '#fff'
    },
    // 生图成功专用
    success: {
      type: Boolean,
      value: false,
      observer(newV, oldV) {
        // console.log('生图成功专用', newV, oldV);
      }
    }
  },
  lifetimes: {
    attached: function () {
      let systemInfo = wx.getSystemInfoSync()
      let rect = wx.getMenuButtonBoundingClientRect()
      // console.log('状态栏',systemInfo.statusBarHeight);
      // console.log('胶囊高度',rect.height);
      // console.log('胶囊距离顶部位置',rect.top);
      // console.log('胶囊距离状态栏底部位置',rect.top-systemInfo.statusBarHeight);
      // console.log('nav的padding',(rect.top-systemInfo.statusBarHeight)*2);
      // console.log('nav的高度',(rect.top-systemInfo.statusBarHeight)*2+rect.height);
      this.setData({
        navTop: systemInfo.statusBarHeight,
        navHeight: (rect.top - systemInfo.statusBarHeight) * 2 + rect.height
      })
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  /**
   * 组件的初始数据
   */
  data: {
    navTop: 0, //navBar距离顶部位置
    navHeight: 0, //navBar高度
    navObjWid: app.globalData.navObjWid
  },

  /**
   * 组件的方法列表
   */
  methods: {
    // 页面跳转
    toPage() {
      // console.log('路径',this.properties.path);
      let _this = this
      if (!_this.properties.path) {
        wx.navigateBack()
      } else {
        wx.navigateTo({
          url: _this.properties.path,
          fail() {
            // console.log('跳转失败',_this.properties.path);
            wx.switchTab({
              url: _this.properties.path,
              success() {
                if (_this.properties.path === '/pages/ai/index') {
                  wx.removeStorageSync('drawingParameter')
                  wx.removeStorageSync('createImgInfo')
                }
                // console.log("tabbar1");
              },
              fail() {
                // console.log("tabbar2");
              }
            })
          }
        })
      }
    },
    // 去反馈
    goFeedback(){
      console.log('去反馈');
      wx.navigateTo({
        url: '/pages/ai/createImgFeedback/index',
      })
    }
  }
})